package com.jason.exp.api;

import com.jason.exp.api.proto.RegionDto;
import com.jason.exp.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/regions")
public class RegionRestController {

    @Autowired
    private RegionService regionService;

    @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public List<RegionDto> regions() {
        List<RegionDto> result = regionService.findAll();
        return result;
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public RegionDto getRegionById(@PathVariable("id") Integer id) {
        RegionDto result = regionService.findById(id);
        return result;
    }

}
